package lgq.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lgq.service.EmpManager;
import lgq.service.TeacherManager;
import model.Emp;
import model.Teacher;
import util.Page;

public class GetAllEmp extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int pageNo=1;
		int pageSize=10;
		String keycode="";
		
		if (null != request.getParameter("serchtype")) {
			request.getSession().setAttribute("serchtype",request.getParameter("serchtype"));
		}
		
		if (null != request.getParameter("keycode")) {
			request.getSession().setAttribute("keycode",request.getParameter("keycode"));
			keycode = request.getParameter("keycode");
		} else {
			keycode = (String) request.getSession().getAttribute("keycode");
		}
		try{
			if(request.getParameter("pageNo")!=null)
			{
				pageNo=Integer.parseInt(request.getParameter("pageNo"));
			}
			if(request.getParameter("pageSize")!=null)
			{
				pageSize=Integer.parseInt(request.getParameter("pageSize"));
				
				request.getSession().setAttribute("pageSize", pageSize);
			}
			if(request.getSession().getAttribute("pageSize")!=null)
			{
				pageSize=(Integer) request.getSession().getAttribute("pageSize");
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		Page<Emp> page=null;
		String name=(null==request.getParameter("name"))?"":request.getParameter("name");
		String age=(null==request.getParameter("age"))?"":request.getParameter("age");
		String sex=(null==request.getParameter("sex"))?"":request.getParameter("sex");
		String edu=(null==request.getParameter("edu"))?"":request.getParameter("edu");
		String skill=(null==request.getParameter("skill"))?"":request.getParameter("skill");
		page=new EmpManager().getByCode(pageNo, pageSize, name, sex, edu, skill);
		//page=new EmpManager().getAll(pageNo, pageSize);	
		
		request.setAttribute("page", page);
		request.getRequestDispatcher("/Dossier/ShowEmp.jsp").forward(request, response);
	}

}
